package org.com.yz.dubbo.web.ctrl;

import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringEscapeUtils;
import org.com.yz.common.annotion.UniformDistribution;
import org.com.yz.common.constant.PayConstant;
import org.com.yz.common.util.ClassRefUtil;
import org.com.yz.dal.dao.model.RequestBaseInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * 请求转发控制类
 *
 * @ClassName SameDistributionctr
 * @Author wzc
 * @Date 2018/7/25 16:13
 **/
@RestController
public class SameDistributionCtr {

    @Autowired
    private MchsubBindBanKcardCtr mchsubBindBanKcardCtr;
    @Autowired
    private BatchCreateMchSubCtr batchCreateMchSubCtr;
    @Autowired
    private SelectMachAccNoCtr selectMachAccNoCtr;
    @Autowired
    private CreateMchSubController createMchSubController;
    @Autowired
    private DispatchMchAccntController dispatchMchAccntController;
    @Autowired
    private PresentQueryCtr presentQueryCtr;
    @Autowired
    private WithDrawMchAccntController withDrawMchAccntController;
    @Autowired
    private BalanceQueryCtr balanceQueryCtr;
    @Autowired
    private NostroAccountCtr nostroAccountCtr;

    /**
     * @param data,sing
     * @Description:统一分发控制器
     * @author wzc
     * @date 2018/7/25 16:15
     */
    @RequestMapping(value = "/api/deposit.htm", method = RequestMethod.POST)
    @UniformDistribution
    public String sameDistribution(String data, String sign) {

        RequestBaseInfo requestBaseInfo = JSONObject.parseObject(StringEscapeUtils.unescapeJava(data), RequestBaseInfo.class);

        if ("mchsub.create".equals(requestBaseInfo.getBizType())) {    //  开设子商户
            return createMchSubController.createMchSubMchAccnt(data, sign);
        }
        if ("mchsub.bind.bankcard".equals(requestBaseInfo.getBizType())) {    //子商户绑定银行卡
            return mchsubBindBanKcardCtr.bankcard(data, sign);
        }
        if ("mchsub.unbind.bankcard".equals(requestBaseInfo.getBizType())) {    //子商户解绑
            return mchsubBindBanKcardCtr.bankcardUntie(data, sign);
        }
        if ("mchsub.batchcreate".equals(requestBaseInfo.getBizType())) {    //批量开设子商户
            return batchCreateMchSubCtr.batchCreateMchSub(data, sign);
        }
        if ("mchsub.query".equals(requestBaseInfo.getBizType())) {    //子商户账户查询
            return selectMachAccNoCtr.selectMachAccNo(data, sign);
        }
        if ("mchaccnt.dispatch".equals(requestBaseInfo.getBizType())) {    //商户分账
            return dispatchMchAccntController.dispatchMchAccnt(data, sign);
        }
        if ("mchaccnt.pay.dispatch".equals(requestBaseInfo.getBizType())) {    //商户支付记账
            return dispatchMchAccntController.dispatchPayMchAccnt(data, sign);
        }
        if ("mchaccnt.refund.dispatch".equals(requestBaseInfo.getBizType())) {    //商户退款记账
            return dispatchMchAccntController.dispatchRefundMchAccnt(data, sign);
        }
        if ("mchaccnt.other.dispatch".equals(requestBaseInfo.getBizType())) {    //商户非支付退款类记账
            return dispatchMchAccntController.dispatchOtherMchAccnt(data, sign);
        }
        if ("mchaccnt.withdraw.query".equals(requestBaseInfo.getBizType())) {    //提现查询
            return presentQueryCtr.presentQuery(data, sign);
        }
        if ("mchaccnt.withdraw".equals(requestBaseInfo.getBizType())) {    //提现
            return withDrawMchAccntController.withDrawMchAccnt(data, sign);
        }
        if ("mchaccnt.balance.query".equals(requestBaseInfo.getBizType())) {    //余额查询
            return balanceQueryCtr.balanceQuery(data, sign);
        }
        if ("mchsub.bind.nostro".equals(requestBaseInfo.getBizType())) {    //往账
            return nostroAccountCtr.nostroAccount(data, sign);
        }

        return ClassRefUtil.createRetData(requestBaseInfo, requestBaseInfo, PayConstant.RETURN_DEPOSIT_CODE_ERROR, "请求参数不合法");

    }


}
